package com.app.twth.ui.b2bpick;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.app.twth.databinding.ItemB2bPickDetailsListBinding;
import com.app.twth.utils.Utils;

import java.util.ArrayList;
import java.util.List;


public class B2BPickDetailsAdapter extends RecyclerView.Adapter<B2BPickDetailsAdapter.MyViewHolder> {
    private int index = -1;
    private LayoutInflater mInflater;
    private List<B2BPick.Details> data = new ArrayList<>();

    public B2BPickDetailsAdapter(Context mContext, List<B2BPick.Details> data) {
        this.data = data;
        this.mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<B2BPick.Details> data, int index) {
        this.data = data;
        this.index = index;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(ItemB2bPickDetailsListBinding.inflate(mInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ItemB2bPickDetailsListBinding itemBinding;

        public MyViewHolder(ItemB2bPickDetailsListBinding itemBinding) {
            super(itemBinding.getRoot());
            this.itemBinding = itemBinding;
        }

        public void setData(int position) {
            itemView.setTag(position);
            B2BPick.Details details = data.get(position);
            itemBinding.tvSku.setText(Utils.getStr(details.getSku()));
            itemBinding.tvQty.setText(Utils.getStr2Int(details.getQty()));
            itemBinding.tvPending.setText(Utils.getStr2Int(details.getPickedQty()));
        }
    }

}
